package uk.co.accolade.clash.core.message;

public class MessageParserFactory {

    public static MessageParser getParserForMessage( String message ) {
        String header = extractVersion(message);
        if( header.equalsIgnoreCase( "V0" ) ) {
            return new MessageParser_V0();
        } else if( header.equalsIgnoreCase( "V1" ) ) {
            return new MessageParser_V1();
        }
        throw new ClashEventParseException( "Message header [" + header + "] could not be recognised." );
    }

    private static String extractVersion( String message ) {
        String[] tokens = message.split("::");
        if( tokens.length != 2 ) {
            return "V0";
        }
        return tokens[0];
    }
}